const CompressionPlugin=require("compression-webpack-plugin")
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const package = require("./package.json")

var BASE_URL='./'
console.log(process.env.DeployType);
if(process.env.DeployType&&process.env.DeployType.startsWith('cdn')){
	//根据配置将资源地址修改为cdn域名
	console.log('部署方式：'+(process.env.DeployType||"默认"))
	var folder=process.env.outputDir
	BASE_URL=package.buildConfig.cdn.oss.url+'/'+package.name+'/'+folder+'/'
	console.log('资源地址：'+BASE_URL)
}


module.exports={
	publicPath: BASE_URL,
	assetsDir: "static",
	lintOnSave: false,
	productionSourceMap: false,
	configureWebpack:config=>{
		config.plugins.push(
			//开启gzip
			// new CompressionPlugin({
			// 	test: /\.(js|css)$/, // 匹配文件名
			// 	threshold: 10240, // 对超过10k的数据压缩
			// 	minRatio: 0.8,
			// 	deleteOriginalAssets: false // 删除源文件
			// })
		)
		return {
			output: { // 输出重构  打包编译后的 文件名称  【项目名称.版本号.hash】
				filename: `static/js/[name].${package.name}.v${package.version}.[hash].js`,
				chunkFilename: `static/js/[name].${package.name}.v${package.version}.[hash].js`
			},
		}
	},
	css: {
		loaderOptions: {
		  less: {
			lessOptions: {
			  modifyVars: {
				'primary-color': '#F26909',
			  },
			  javascriptEnabled: true,
			},
		  },
		},
	},
	devServer:{
		host:"0.0.0.0"
	}
}
